package com.gxa.meiye.admin.platform.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.meiye.admin.platform.mapper.AppraiseMapper;
import com.gxa.meiye.admin.platform.pojo.vo.*;
import com.gxa.meiye.admin.platform.service.AppraiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AppraiseServiceImpl extends ServiceImpl<AppraiseMapper, AppraiseVo> implements AppraiseService {

    @Autowired
    private AppraiseMapper appraiseMapper;


    @Override
    public List<AppListVo> selectAppraList() {
        List<AppraiseVo> appraiseVos = appraiseMapper.selectList(null);
        List<AppListVo> appListVos = new ArrayList<>();
        for (AppraiseVo a :appraiseVos) {
            AppListVo appListVo = new AppListVo();
            appListVo.setOrderId(a.getOrderId());
            appListVo.setId(a.getId());
            appListVo.setGrade(a.getGrade());
            appListVo.setText(a.getContent());
            appListVo.setPic(a.getImages());
            System.out.println(a.getUserId());
            SelectAppUserVo selectAppUserVo = appraiseMapper.selectUserById(a.getUserId());
            appListVo.setPhone(selectAppUserVo.getPhone());
            appListVo.setUserName(selectAppUserVo.getName());
            System.out.println(a.getOrderId());
            SelectAppShopVo selectAppShopVo = appraiseMapper.selectShopById(a.getOrderId());
            if(selectAppShopVo.getShopId()==null||selectAppShopVo.getShopId().equals("")){
                String s = appraiseMapper.selectTherapistName(selectAppShopVo.getTherapistId());
                appListVo.setShopName(s);
            }else {
                String s = appraiseMapper.selectShopName(selectAppShopVo.getShopId());
                appListVo.setShopName(s);
            }
            appListVos.add(appListVo);
        }
        return appListVos;
    }

    @Override
    public List<AppListVo> selectAppraises(String select) {
        List<AppraiseVo> appraiseVos = appraiseMapper.selectAppraise(select);
        List<AppListVo> appListVos = new ArrayList<>();
        for (AppraiseVo a :appraiseVos) {
            AppListVo appListVo = new AppListVo();
            appListVo.setId(a.getOrderId());
            appListVo.setGrade(a.getGrade());
            appListVo.setText(a.getContent());
            appListVo.setPic(a.getImages());
            SelectAppUserVo selectAppUserVo = appraiseMapper.selectUserById(a.getUserId());
            appListVo.setPhone(selectAppUserVo.getPhone());
            appListVo.setUserName(selectAppUserVo.getName());
            SelectAppShopVo selectAppShopVo = appraiseMapper.selectShopById(a.getOrderId());
            if(selectAppShopVo.getShopId()==null||selectAppShopVo.getShopId().equals("")){
                String s = appraiseMapper.selectTherapistName(selectAppShopVo.getTherapistId());
                appListVo.setShopName(s);
            }else {
                String s = appraiseMapper.selectShopName(selectAppShopVo.getShopId());
                appListVo.setShopName(s);
            }
            appListVos.add(appListVo);
        }
        return appListVos;
    }

    @Override
    public Integer delAppraise(Integer id) {
        int i = appraiseMapper.deleteById(id);
        return i;
    }
}
